using System;
using NUnit.Framework;
using OpenRay;

namespace Tests
{
	[TestFixture]
	public class TestVector
	{
		[Test]
		public void TestVectorSet()
		{
			Vector v = new Vector(0f, 1f, 2f);
			
			Assert.AreEqual( 0f, v.X );
			Assert.AreEqual( 1f, v.Y );
			Assert.AreEqual( 2f, v.Z );
		}
		
		[Test]
		public void TestDotProduct()
		{
			Vector v = new Vector(0, 1, 2);
			Vector t = new Vector(4, 3, 2);
			
			Assert.AreEqual( 5f, Vector.DotProduct(v,v) );
			Assert.AreEqual( 7f, Vector.DotProduct(v,t) );
		}
		
		[Test]
		public void TestLength()
		{
			Vector v = new Vector(0, 0, 1);
			Vector t = new Vector(0, 2, 0);
			
			Assert.AreEqual( 1f, v.Length() );
			Assert.AreEqual( 2f, t.Length() );
		}
		
		[Test]
		public void TestNormalize()
		{
			Vector v = new Vector(3, 1, 2);
			Assert.IsFalse( v.IsNormal() );
			
			v = Vector.Normalize( v );
			Vector t = new Vector( 0.8017837f, 0.2672612f, 0.5345225f );
			
			Assert.IsTrue( t.Equals( v ) );
			Assert.IsTrue( v.IsNormal() );
		}
		
		[Test]
		public void TestReverse()
		{
			Vector v = new Vector(0, 1, 2);
			Vector t = new Vector(0, -1, -2);
			
			Assert.AreEqual( v, -t );
		}
		
		[Test]
		public void TestAdd()
		{
			Vector v = new Vector(0, 1, 2);
			Vector t = new Vector(1, 2, 3);
			
			Assert.AreEqual( new Vector(1, 3, 5), v + t );
		}
		
		[Test]
		public void TestSubtract()
		{
			Vector v = new Vector(0, 1, 2);
			Vector t = new Vector(1, 2, 3);
			
			Assert.AreEqual( new Vector(-1, -1, -1), v - t );
		}
		
		[Test]
		public void TestScale()
		{
			Vector v = new Vector(-1, 1, 1);
			Vector t = new Vector(-2, 2, 2);
			
			Assert.AreEqual( t, v * 2 );
			Assert.AreEqual( t, 2 * v );
		}
		
		[Test]
		public void TestCrossProduct()
		{
			Vector v = new Vector( 1, 2, 3);
			Vector t = new Vector( 3, 2, 1);
			
			Assert.AreEqual( new Vector( -4, 8, -4 ), Vector.CrossProduct(v,t) );
		}
		
		[Test]
		public void TestReflect()
		{
			Vector v = new Vector(0f, 0f, -1f);
			Vector t = new Vector(0f, 0f, 1f);
			Assert.AreEqual( t, Vector.Reflect(v, t) );
			
			v = new Vector(0.70710678f, 0f, 0.70710678f);
			Assert.IsTrue( new Vector(0.70710678f, 0f, -0.70710678f).Equals( Vector.Reflect(v,t) ) );
		}
		
		[Test]
		public void TestHalfAngle()
		{
			Vector v = new Vector(0f, 0f, 1f);
			Vector t = new Vector(0f, 1f, 0f);
			Vector r = new Vector(0f, 0.707106781f, 0.707106781f);
			
			Assert.AreEqual(r, Vector.HalfAngle(v, t));
		}
	}
}

